package com.syspeak.makereap.domain.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * Dept generated by Lingo.
 *
 * @author Lingo
 * @since 2007年08月18日 下午 20时18分45秒0
 */
@Entity
@Table(name = "WEB_DEPT")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Dept implements Serializable {
	/** * serial. */
	static final long serialVersionUID = 0L;

	/** * id. */
	private Long id;

	/** * parent. */
	private Dept parent;

	/** * name. */
	private String name;

	/** * theSort. */
	private Integer theSort;

	/** * descn. */
	private String descn;

	/** * children. */
	private Set<Dept> children = new HashSet<Dept>(0);

	/** * users. */
	private Set<User> users = new HashSet<User>(0);

	/** * 构造方法. */
	public Dept() {
	}

	/** * @return id. */
	@GenericGenerator(name = "generator", strategy = "increment")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "ID", nullable = false)
	public Long getId() {
		return id;
	}

	/** * @param id id. */
	public void setId(Long id) {
		this.id = id;
	}

	/** * @return parent. */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PARENT_ID")
	public Dept getParent() {
		return parent;
	}

	/** * @param parent Dept. */
	public void setParent(Dept parent) {
		this.parent = parent;
	}

	/** * @return name. */
	@Column(name = "NAME", length = 200)
	public String getName() {
		return name;
	}

	/** * @param name name. */
	public void setName(String name) {
		this.name = name;
	}

	/** * @return theSort. */
	@Column(name = "THE_SORT")
	public Integer getTheSort() {
		return theSort;
	}

	/** * @param theSort Integer. */
	public void setTheSort(Integer theSort) {
		this.theSort = theSort;
	}

	/** * @return descn. */
	@Column(name = "DESCN", length = 200)
	public String getDescn() {
		return descn;
	}

	/** * @param descn descn. */
	public void setDescn(String descn) {
		this.descn = descn;
	}

	/** * @return children. */
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
	@OrderBy("theSort asc, id desc")
	public Set<Dept> getChildren() {
		return children;
	}

	/** * @param children Set. */
	public void setChildren(Set<Dept> children) {
		this.children = children;
	}

	/** * @return users. */
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "dept")
	public Set<User> getUsers() {
		return users;
	}

	/** * @param users users. */
	public void setUsers(Set<User> users) {
		this.users = users;
	}
}
